﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrogEngine;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace TestGame
{
	class TestEngine : Engine
	{
		public TestEngine(Game game, GameWindow window, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, ContentManager contentManager)
			: base(game, window, graphicsDevice, spriteBatch, contentManager)
		{
		}

		public override void Initialize()
		{
			entityServices.Add(new GamePadInputService(this));
			entityServices.Add(new KeyboardInputService(this));
			entityServices.Add(new MouseInputService(this));
			entityServices.Add(new GameContentService(this));
			entityServices.Add(new ParticleService(this));
			var renderService = new RenderService(this);
			entityServices.Add(renderService);
			var updateService = new UpdateEntityService(this);
			entityServices.Add(updateService);

			var gameState = new GameStateManagementService(this);
			entityServices.Add(gameState);

			var gameplayScreen = new GameplayScreen(this);
			gameState.Subscribe(gameplayScreen);
			gameState.ScreenManager.Transition(gameplayScreen);

			//var testScreen = new TestScreen(this, "state1");
			//var testScreen2 = new TestScreen(this, "state2");
			//testScreen.AddTransition(testScreen2);
			//testScreen2.AddTransition(testScreen);
			//gameState.Subscribe(testScreen);
			//gameState.Subscribe(testScreen2);
			//gameState.ScreenManager.Transition(testScreen);

			var cameraService = new CameraService(this);
			entityServices.Add(cameraService);

			var plane = new TestPlaneModelEntity(this, "Ground");
            List<CollisionModel> models = new List<CollisionModel>();
            Random r = new Random();
            //for (int i = 0; i < 30; i++)
            //{
            //    int x = r.Next(0, 20000);
            //    int y = r.Next(0, 20000);
            //    int z = r.Next(0, 20000);
            //    var ship = new CollisionModel(this, "MikuHatsuneMMD");
            //    ship.Position = new Vector3(x, 1800 + y, z);
            //    models.Add(ship);
            //}
            var ship = new CollisionModel(this, "MikuHatsuneMMD");
            ship.Position = new Vector3(0, 1800, 0);
			var camera = new FirstPersonCamera(this, ship, 10f);

			//StatefulParticleSystem particleSystem = new StatefulParticleSystem(this);
			//StatefulParticleSystem particleSystem2 = new StatefulParticleSystem(this);
			//StatefulParticleSystem particleSystem3 = new StatefulParticleSystem(this);
			//StatefulParticleSystem particleSystem4 = new StatefulParticleSystem(this);
			//StatefulParticleSystem particleSystem5 = new StatefulParticleSystem(this);
			//var fireParticleSystem = new FireParticleSystem(this);
			//var fireEmitter = new FireParticleEmitter(this);
			//fireEmitter.Position = new Vector3(0, 800, 0);

			var fps = new FpsDisplay(this);

			//camera.Forward = Vector3.Forward;
			//camera.Right = Vector3.Right;
			//camera.Up = Vector3.Up;
			camera.World = Matrix.Identity;
			cameraService.Subscribe(camera);
			cameraService.SetActiveCamera(camera);

		}

		public override void Cleanup()
		{
			entityServices.Clear();
			entities.Clear();
		}
	}
}
